//
//  LogCell.m
//  FreeTrip
//
//  Created by 邓芮 on 15/11/24.
//  Copyright © 2015年 邓芮. All rights reserved.
//

#import "LogCell.h"

@interface LogCell ()
@property (nonatomic, strong) UIView *headerView;
// 发布者头像
@property (nonatomic, strong) UIImageView *headerImageView;
// 发布者名字
@property (nonatomic, strong) UILabel *nameLabel;
// 图片显示
@property (nonatomic, strong) UIImageView *icon;
// 发布主题
@property (nonatomic, strong) UILabel *title;
@end

@implementation LogCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = NO;
        CGFloat height = 55 * KScreenWidth / 414;
        self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, height)];
        [self.contentView addSubview:self.headerView];
        
        CGFloat kHeaderWidth = 45 * KScreenWidth / 414;
        self.headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20 * KScreenWidth / 414, 5 * KScreenWidth / 414, kHeaderWidth, kHeaderWidth)];
        self.headerImageView.layer.cornerRadius = kHeaderWidth/2;
        self.headerImageView.layer.masksToBounds = YES;
        
        [self.headerView addSubview:self.headerImageView];
        
        CGFloat kNameWidth = KScreenWidth - (20 + kHeaderWidth + 10);
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20 + kHeaderWidth + 10 , 5, kNameWidth, kHeaderWidth)];
        self.nameLabel.textAlignment = NSTextAlignmentLeft;
        self.nameLabel.textColor = [UIColor grayColor];
        self.nameLabel.font = [UIFont systemFontOfSize:KScreenWidth / 27];
        [self.headerView addSubview:self.nameLabel];
        
        CGFloat iconHeight = KScreenWidth * 470 / 750;
        self.icon = [[UIImageView alloc]initWithFrame:CGRectMake(0, height, KScreenWidth, iconHeight)];
        [self.contentView addSubview:self.icon];
        
        self.title = [[UILabel alloc]initWithFrame:CGRectMake(10, height + iconHeight, KScreenWidth - 20 * KScreenWidth / 414, height)];
        self.title.textColor = [UIColor grayColor];
        self.title.textAlignment = NSTextAlignmentLeft;
        self.title.font = [UIFont systemFontOfSize:KScreenWidth / 24];
        [self.contentView addSubview:self.title];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, height + iconHeight + height, KScreenWidth, 10)];
        label.backgroundColor = [UIColor grayColor];
        label.alpha = 0.4;
        [self.contentView addSubview:label];
        
    }
    return self;
}

- (void)setModel:(LogModel *)model
{
    _model = model;
    [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:model.headicon] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.nameLabel.text = model.nickname;
    [self.icon sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.title.text = model.title;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
